package com.zmj.sy.mom.srv.aps.bean.vo.base;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * 分页数据封装类
 * Created by macro on 2019/4/19.
 */
public class CommonPage<T> {
    @ApiModelProperty(value = "页码")
    private long page;
    @ApiModelProperty(value = "条数")
    private long size;
    @ApiModelProperty(value = "总页数")
    private long pages;
    @ApiModelProperty(value = "总条数")
    private Long total;
    @ApiModelProperty(value = "记录数")
    private List<T> items;

 
	/**
     * 将PageHelper分页后的list转为分页信息
     */
	public static <T> CommonPage<T> restPage(Long  total,List<T> list) {
	    CommonPage<T> result = new CommonPage<T>();
	    result.setTotal(total);
	    result.setItems(list);
	    return result;
	}

    /**
     * 将SpringData分页后的list转为分页信息
     */
    public static <T> CommonPage<T> restPage(Page<T> pageInfo) {
        CommonPage<T> result = new CommonPage<T>();
        result.setPages(pageInfo.getTotalPages());
        result.setPage(pageInfo.getNumber());
        result.setSize(pageInfo.getSize());
        result.setTotal(pageInfo.getTotalElements());
        result.setItems(pageInfo.getContent());
        return result;
    }
    /**
     * @Title: restPage
     * @Description: mybatisplus  页码转换
     * @Author pengxiaodong
     * @DateTime 2022年7月11日 下午3:47:10
     * @param <T>
     * @param pageInfo
     * @return
     */
    public static <T> CommonPage<T> restPage(IPage<T> pageInfo) {
        CommonPage<T> result = new CommonPage<T>();
        result.setPages(pageInfo.getPages());
        result.setPage(pageInfo.getCurrent());
        result.setSize(pageInfo.getSize());
        result.setTotal(pageInfo.getTotal());
        result.setItems(pageInfo.getRecords());
        return result;
    }




    public long getPage() {
        return page;
    }

    public void setPage(long page) {
        this.page = page;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public long getPages() {
        return pages;
    }

    public void setPages(long pages) {
        this.pages = pages;
    }

    public void setPages(Integer pages) {
        this.pages = pages;
    }

    public List<T> getItems() {
        return items;
    }

    public void setItems(List<T> items) {
        this.items = items;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }
}
